#include "p5.h"
#include "p1.h"

#include <bitset>
#include <iostream>



void testDiffDigital() {
    int varOct { 012 };
    int varDec { 10 };
    int varHex { 0xa };
    int varBin { 0b1010 };
    int varBin2 { 0b1001'0001 };

    std::cout << std::dec << varDec << " Decimal: " << std::dec << varDec << '\n';
    std::cout << std::dec << varOct << " Octal: " << std::oct << varOct << '\n';
    std::cout << std::dec << varHex << " Hexadecimal: " << std::hex << varHex << '\n';

    std::cout << std::dec << varBin << " Binary: " << std::bitset<4>(varBin) << '\n';
    std::cout << std::dec << varBin2 << " Binary: " << std::bitset<8>(varBin2) << '\n';

}



TestVROAndNVRO funcTestNVRO() {
    TestVROAndNVRO t;
    return t;  // 可能不会看到 "Copied"，因为 NRVO 可以省略复制
}


void testInlineFunc() {
    for (int i = 0; i < 5; ++i) {
        std::cout << "Square of " << i << " is " << squareInline(i) << '\n';
    }
}


constexpr std::string_view getQuantityPhrase(int param) {
    if (param < 0) {
        return "negative";
    } else if (param == 0) {
        return "no";
    } else if (param == 1) {
        return "a single";
    } else if (param == 2) {
        return "a couple of";
    } else if (param == 3) {
        return "a few";
    } else {
        return "many";
    }
}


constexpr std::string_view getApplesPluralized(int param) {
    return (param == 1) ? "apple" : "apples";
}

void testHomeWork6() {
    constexpr int maryApples { 3 };
    std::cout << "Mary has " << getQuantityPhrase(maryApples) << ' ' << getApplesPluralized(maryApples) << ".\n";

    std::cout << "How many apples do you have? ";
    int numApples { };
    std::cin >> numApples;

    std::cout << "You have " << getQuantityPhrase(numApples) << ' ' << getApplesPluralized(numApples) << ".\n";
}
